package test.core.data;

import hyl.core.MyDate;
import hyl.core.MyFun;
import hyl.core.data.BlockValue;
import hyl.core.data.BlockValue2;
import hyl.core.data.ExBlockMap;
import hyl.core.run.MyRun;

public class testblockvalue {

	public static void main(String[] dfd) {
		//test1_1();
		//test1_2();
		//test1_3();
		//test1_4();
		//test1_5() ;
		test1_1_2() ;
	}
	
	public static void test1_1() {
		BlockValue<String> bm = new BlockValue<String>(5000);

		MyRun.start用户线程(() -> {
			System.out.println(bm.get());
			MyDate.sleeps(1);
			System.out.println(bm.get());

		});
		MyRun.start用户线程(() -> {
			MyDate.sleeps(2);
			bm.set("ss");
			bm.set("ss2");
			MyDate.sleeps(4);
			bm.set("sds");
		});
	}
	public static void test1_1_2() {
		BlockValue2<String> bm = new BlockValue2<String>(5000);

		MyRun.start用户线程(() -> {
			System.out.println(bm.get());
			MyDate.sleeps(1);
			System.out.println(bm.get());

		});
		MyRun.start用户线程(() -> {
			MyDate.sleeps(2);
			bm.set("ss");
			bm.set("ss2");
			MyDate.sleeps(4);
			bm.set("sds");
		});
		
	}

	public static void test1_2() {
		BlockValue<String> bm = new BlockValue<String>(5000);

		MyRun.start用户线程(() -> {
			for (int i = 0; i < 10000; i++) {
				System.out.println(bm.get());
			}
		});
		MyRun.start用户线程(() -> {
			for (int i = 0; i < 10000; i++) {
				bm.set("ss" + i);
			}
		});

	}

	public static void test1_3() {
		BlockValue2<String> bm = new BlockValue2<String>(5000);

		MyRun.start用户线程(() -> {
			for (int i = 0; i < 10000; i++) {
				System.out.println(bm.get());
			}
		});
		MyRun.start用户线程(() -> {
			for (int i = 0; i < 10000; i++) {
				bm.set("ss" + i);
			}
		});

	}
	public static void test1_4() {
		BlockValue<String> bm = new BlockValue<String>(2000);

		MyRun.start用户线程(() -> {
			for (int i = 0; i < 9; i++) {
				System.out.println(bm.get());
			}
		});
		MyRun.start用户线程(() -> {
			for (int i = 0; i < 3; i++) {
				MyDate.sleeps(3);
				bm.set("ss" + i);
			}
		});

	}
	
	public static void test1_5() {
		BlockValue<String> bm = new BlockValue<String>(3000);

		MyRun.start用户线程(() -> {
			for (int i = 0; i < 4; i++) {
				System.out.println(bm.get());
				MyDate.sleeps(2);
			
			}
		});
		MyRun.start用户线程(() -> {
			for (int i = 0; i < 3; i++) {	
				MyDate.sleeps(1);
				bm.set("ss" + i);
			}
		});

	}
	public void test2_2() {
		long st = MyFun.getMs();
		for (int i = 0; i < 100000; i++) {
			BlockValue<String> bm = new BlockValue<String>(3000);
		}
		st = MyFun.getMs() - st;
		MyFun.print("耗时", st);

		st = MyFun.getMs();
		BlockValue<String> bm1 = new BlockValue<String>(3000);
		for (int i = 0; i < 100000; i++) {
			BlockValue<String> bm2 = (BlockValue<String>) bm1.clone();
		}
		st = MyFun.getMs() - st;
		MyFun.print("耗时", st);
	}
}
